package com.morihacky.android.rxjava;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

/**
 * Created by zhangchong on 16/2/28.
 * testRecyclerView
 */
public class Activity_test_rvanimation extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getRv(),new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }
    View getRv(){
        RecyclerView view = new RecyclerView(this);
        view.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));
        view.setHasFixedSize(true);
        view.setAdapter(new TestAdapter());
        return view;
    }
    class  TestAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
       ;
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            TextView v  = new TextView(parent.getContext());
            return new ViewHolder(v);
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            TextView v = (TextView)holder.itemView;
            v.setText(position + "aha");
            v.postDelayed(() -> v.startAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.anim_rvitem)), position*100);

        }

        @Override
        public int getItemCount() {
            return 100;
        }
        class ViewHolder extends RecyclerView.ViewHolder{

            public ViewHolder(View itemView) {
                super(itemView);

            }
        }
    }
}
